package com.vtest.quartz.task;

import com.vtest.quartz.domain.needle.LocEntity;
import com.vtest.quartz.mapper.needle.NeedleMapper;
import com.vtest.quartz.service.needle.NeedleService;
import com.vtest.quartz.utils.others.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @program: Quartz
 * @author: tiger
 * @create: 2024-12-12 17:04
 * @Description :定时任务调度测试
 */

@Component("ryTask")
@Slf4j
public class RyTask {

    @Autowired
    private NeedleMapper mapper;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) throws InterruptedException {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
        log.debug(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
        Thread.sleep(10000);
    }

    public void ryParams(String params) throws InterruptedException {
        System.out.println("执行有参方法：" + params);
        log.debug("执行有参方法：{}" , params);
        Thread.sleep(10000);
    }

    public void ryNoParams() throws IOException {
        System.out.println("执行无参方法");

        //HashMap<String, String> map = new HashMap<>();

        ArrayList<LocEntity> locEntitiesList = new ArrayList<>();

        FileInputStream in = null;
        //in = new FileInputStream(System.getProperty("user.dir") + "file/template/URNFTP Probecard Status.xlsx");
        //in = new FileInputStream(System.getProperty("user.dir") + "/URNFTP Probecard Status.xlsx");
        in = new FileInputStream("C:\\Users\\5163\\Desktop\\修改库位.xlsx");
        Workbook workbook = new XSSFWorkbook(in);
        //获取第一个sheet
        Sheet sheet0 = workbook.getSheetAt(0);
        int lastRowNum = sheet0.getLastRowNum();

        for (int i = 1; i <= lastRowNum; i++) {


            Row row = sheet0.getRow(i);
            if (row == null) continue;
            Cell cellProber = row.getCell(0);
            if (cellProber == null) continue;
            String prober = cellProber.getStringCellValue();

            Cell beforeLocCell = row.getCell(1);
            String beforeLoc = beforeLocCell.getStringCellValue();

            Cell locCell = row.getCell(2);
            String loc = locCell.getStringCellValue();

            //map.put(prober, type);

            LocEntity locEntity = new LocEntity();
            locEntity.setId(prober);
            locEntity.setLoc(loc);
            locEntity.setBeforeLoc(beforeLoc);
            locEntitiesList.add(locEntity);
        }

        for (LocEntity locEntity : locEntitiesList) {
            mapper.updateLocByID(locEntity);
        }


    }
}
